# 在不影响原代码情况下添加重试功能
from retry_decorators import retry_can
from loguru import logger

class ZCANWrapper:
    """
    ZCAN 类的包装器，添加重试功能
    """
    def __init__(self, zcan_instance):
        self.zcan = zcan_instance

    @retry_can
    def OpenDevice(self, device_type, device_index, reserved):
        return self.zcan.OpenDevice(device_type, device_index, reserved)

    @retry_can
    def CloseDevice(self, device_handle):
        return self.zcan.CloseDevice(device_handle)

    @retry_can
    def GetDeviceInf(self, device_handle):
        return self.zcan.GetDeviceInf(device_handle)

    @retry_can
    def DeviceOnLine(self, device_handle):
        return self.zcan.DeviceOnLine(device_handle)

    @retry_can
    def InitCAN(self, device_handle, can_index, init_config):
        return self.zcan.InitCAN(device_handle, can_index, init_config)

    @retry_can
    def StartCAN(self, chn_handle):
        return self.zcan.StartCAN(chn_handle)

    @retry_can
    def ResetCAN(self, chn_handle):
        return self.zcan.ResetCAN(chn_handle)

    @retry_can
    def ClearBuffer(self, chn_handle):
        return self.zcan.ClearBuffer(chn_handle)

    @retry_can
    def ReadChannelErrInfo(self, chn_handle):
        return self.zcan.ReadChannelErrInfo(chn_handle)

    @retry_can
    def ReadChannelStatus(self, chn_handle):
        return self.zcan.ReadChannelStatus(chn_handle)

    @retry_can
    def GetReceiveNum(self, chn_handle, can_type):
        return self.zcan.GetReceiveNum(chn_handle, can_type)

    @retry_can
    def Transmit(self, chn_handle, std_msg, len):
        return self.zcan.Transmit(chn_handle, std_msg, len)

    @retry_can
    def Receive(self, chn_handle, rcv_num, wait_time):
        return self.zcan.Receive(chn_handle, rcv_num, wait_time)

    @retry_can
    def TransmitFD(self, chn_handle, fd_msg, len):
        return self.zcan.TransmitFD(chn_handle, fd_msg, len)

    @retry_can
    def ReceiveFD(self, chn_handle, rcv_num, wait_time):
        return self.zcan.ReceiveFD(chn_handle, rcv_num, wait_time)

    @retry_can
    def GetIProperty(self, device_handle):
        return self.zcan.GetIProperty(device_handle)

    @retry_can
    def SetValue(self, iproperty, path, value):
        return self.zcan.SetValue(iproperty, path, value)

    @retry_can
    def GetValue(self, iproperty, path):
        return self.zcan.GetValue(iproperty, path)

    @retry_can
    def ReleaseIProperty(self, iproperty):
        return self.zcan.ReleaseIProperty(iproperty)